home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 1006 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.3 KB

  1. From: Rob Stewart <stew@datalytics.com>
  2. Message-ID: <316958BE.28E5@datalytics.com>
  3. X-Original-Date: Mon, 08 Apr 1996 14:19:42 -0400
  4. Path: in1.uu.net!bounce-back
  5. Date: 08 Apr 96 18:44:22 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Newsgroups: comp.std.c++
  8. Subject: Re: Must exception classes have copy constructors?
  9. Organization: Datalytics, Inc
  10. References: <606373375wnr@ma.ccngroup.com> <4k6130$l22@engnews1.Eng.Sun.COM>
  11. X-Mailer: Mozilla 2.0 (WinNT; I)
  12. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  13.     iQBFAgUBMWlej+EDnX0m9pzZAQFRigF+J6viPD5FKYOILbFD/iaBh6JCF3aYVS1n
  14.     qhg4Fc/awej0KnmN4fsf1/Dv/99WXfgg
  15.     =9ykZ
  16.  
  17. Steve Clamage wrote:
  18. > Alan Griffiths <aGriffiths@ma.ccngroup.com> writes:
  19. > >I've just tried porting some code to MSVC4 (it compiles and works with
  20. > >SC7.1 and BC4.5).
  21. > >In effect it appears that the Microsoft compiler _requires_ anything
  22. > >thrown as an exception to have an accessible copy constructor.  (I've
  23. > >tended to make copy constructors private to ensure catch-by-reference
  24. > >and aviod slicing bugs.)
  25. > According to the draft standard, when you throw something, what is
  26. > thrown is actually a copy of that something. If the copy constructor
  27. > for that something is not accessible, the copy can't be made.
  28. > [snip]
  29.  
  30. > In your case, you will probably have to throw a pointer instead
  31. > of a value, if the type has a private copy constructor.
  32.  
  33. You'll have to implement an exception object management policy.  
  34. (I know the exception is actually the pointer to some class, 
  35. but I'm using "exception object" to mean the object pointed 
  36. to by that exception.)  You must allocate your exception objects 
  37. on the heap, and delete them in the final catch block.  That is, 
  38. so long as you throw the pointer up the stack, as it were, you 
  39. cannot delete what the pointer points to.  Only in the catch 
  40. block in which you no longer rethrow the exception can you 
  41. delete the memory (exception object) it points to.
  42.  
  43. -- 
  44. Robert Stewart        | My opinions are usually my own.
  45. Datalytics, Inc.    | stew@datalytics.com
  46. ---
  47. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  48. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  49. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  50. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  51. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  52.